package com.foosun.core.base;

import com.alibaba.fastjson.JSON;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * entity基类.
 */
public class BaseEntity implements Serializable {
    protected Integer id;
    protected Date insertTime = new Date();
    protected Date lastUpdateTime = new Date();

    public Map<String, Object> getEntityMap() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("insert_time", insertTime);
        map.put("last_update_time", lastUpdateTime);
        return map;
    }

    public Object getJson() {
        Map<String, Object> map = this.getEntityMap();
        map.put("id", id);
        Object json = JSON.toJSON(map);
        return json;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getInsertTime() {
        return insertTime;
    }

    public void setInsertTime(Date insertTime) {
        this.insertTime = insertTime;
    }

    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    /**
     * 是否是新对象
     *
     * @return
     */
    public boolean isNew() {
        return (this.id == null);
    }

}
